package com.yingdong.sceneserver.inner.service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yingdong.utils.HttpUtils;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;

public class HttpService {
	private static Map<String, HttpHandler> handlerMap = new ConcurrentHashMap<>();
	static Log logger = LogFactory.getLog(HttpService.class);

	public static void handleHttpRequest(ChannelHandlerContext ctx, HttpRequest request) {
		String op = HttpUtils.getParamerByNameFromGET(request, "op");
		if (handlerMap.containsKey(op)) {
			try {
				handlerMap.get(op).httpHandle(ctx, request);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				logger.info("", e);
			}
		}

	}

	public static void registHandler(String op, HttpHandler handler) {
		handlerMap.put(op, handler);
	}

}
